var vm = new Vue({
    el: '#registerInfo', //el指定一个页面中已存在的DOM元素来挂载VUE实例
    data: {
        registerInfo: {},
        flag:true
    },
    created: function () {

    },
    methods: {
        register: function () {
            if(true==this.flag){
                console.log("可以注册");
                axios.request({
                    url: `/user`,
                    method: "post",
                    headers: {
                        'Content-Type': 'application/json' //重点
                    },
                    data: this.registerInfo
                }).then(res=>{
                    if(res.data.code==20000){
                        window.location.href = "/view/login";
                    }
                })
            }
            console.log("进入了vue模型...............");
            console.log(this.registerInfo);
            this.checkPassWord();
        },
        checkUserName: function () {
            axios.request({
                //${this.registerInfo.username}
                url: `/user/checkUserName`,
                method: "post",
                headers: {
                    'Content-Type': 'application/json' //重点
                },
                data: this.registerInfo
            }).then(res => {
                if(res.data.code==20000){
                    this.flag=false;
                    layer.msg("姓名重复，请重新输入");
                    console.log("姓名重复")
                }
                this.flag=true;
            });
        },
        checkEmail: function () {
            axios.request({
                url: `/user/checkEmail`,
                method: "post",
                headers: {
                    'Content-Type': 'application/json' //重点
                },
                data: this.registerInfo
            }).then(res => {
                if(res.data.code==20000){
                    this.flag=false;
                    layer.msg("邮箱重复，请重新输入");
                    console.log("邮箱重复")
                }
                this.flag=true;
            });
        },
        //如果检测到两次密码不一致  改变flag的值
        checkPassWord:function () {
            if(this.registerInfo.password!=this.registerInfo.password1){
                this.flag=false;
                layer.msg("密码不一致，请检测密码")
            }
            this.flag=true;
        }
    }
});